--优惠卷id，用户id
local voucherId = ARGV[1]
local userId = ARGV[2]

local stockKey = 'seckill:stock:' .. voucherId
local orderKey = 'seckill:order:' .. voucherId

--判断库存是否充足 get stockKey
if (tonumber(redis.call('get', stockKey)) <= 0) then
    return 1
end
--判断用户是否下单 sismember orderKey
if (tonumber(redis.call('sismember', orderKey, userId)) == 1) then
    return 2
end
--减库存 incrby stockKey -1
redis.call('incrby', stockKey, -1)
--下单 sadd orderKey userId
redis.call('sadd', orderKey, userId)
return 0